@danielstyle/featflow 0.0.0-stage → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +206 -2
  3. package/README.zh-CN.md +163 -0
  4. package/bin/featflow.mjs +113 -0
  5. package/package.json +62 -4
  6. package/skills/featflow/SKILL.md +127 -0
  7. package/skills/featflow-issues/SKILL.md +104 -0
  8. package/skills/featflow-regression/SKILL.md +63 -0
  9. package/src/agent-docs.mjs +143 -0
  10. package/src/changed-files.mjs +204 -0
  11. package/src/commands/cleanup.mjs +221 -0
  12. package/src/commands/codegraph.mjs +110 -0
  13. package/src/commands/doctor.mjs +265 -0
  14. package/src/commands/finish.mjs +249 -0
  15. package/src/commands/hook-cmd.mjs +78 -0
  16. package/src/commands/hooks-cmd.mjs +238 -0
  17. package/src/commands/init.mjs +382 -0
  18. package/src/commands/issue.mjs +434 -0
  19. package/src/commands/new.mjs +311 -0
  20. package/src/commands/plan-check.mjs +75 -0
  21. package/src/commands/policy-cmd.mjs +51 -0
  22. package/src/commands/pr-cleanup.mjs +194 -0
  23. package/src/commands/regression.mjs +206 -0
  24. package/src/commands/setup.mjs +343 -0
  25. package/src/commands/size-check.mjs +137 -0
  26. package/src/commands/status.mjs +100 -0
  27. package/src/commands/sync.mjs +407 -0
  28. package/src/commands/verify.mjs +206 -0
  29. package/src/commands/worktree.mjs +205 -0
  30. package/src/config.mjs +295 -0
  31. package/src/detect.mjs +314 -0
  32. package/src/git.mjs +331 -0
  33. package/src/hook-adapters.mjs +218 -0
  34. package/src/hooks-core.mjs +420 -0
  35. package/src/index.mjs +13 -0
  36. package/src/init-args.mjs +282 -0
  37. package/src/init-hooks.mjs +312 -0
  38. package/src/init-prompts.mjs +191 -0
  39. package/src/issues-helpers.mjs +463 -0
  40. package/src/issues.mjs +521 -0
  41. package/src/plan.mjs +202 -0
  42. package/src/policy.mjs +143 -0
  43. package/src/regression.mjs +338 -0
  44. package/src/size-check.mjs +203 -0
  45. package/src/tui-select.mjs +378 -0
  46. package/templates/adapters/antigravity/hooks.json +42 -0
  47. package/templates/adapters/claude-code/settings.json +46 -0
  48. package/templates/adapters/codex/config.toml +19 -0
  49. package/templates/adapters/cursor/hooks.json +27 -0
  50. package/templates/agents/codex/codebase-locator.toml +28 -0
  51. package/templates/agents/codex/implementation-scout.toml +28 -0
  52. package/templates/agents/codex/regression-guard-planner.toml +20 -0
  53. package/templates/features/README.md +56 -0
  54. package/templates/features/_program_template.md +79 -0
  55. package/templates/features/_template.md +120 -0
  56. package/templates/features/current-feature.md +18 -0
  57. package/templates/githooks/post-merge +7 -0
  58. package/templates/githooks/pre-commit +11 -0
  59. package/templates/githooks/pre-push +10 -0
  60. package/templates/regression/regression-ledger.yml +23 -0
  61. package/templates/snippets/AGENTS-workflow.md +21 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Daniel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,207 @@
1
- # Temporary Holding Version
1
+ # featflow
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **AI-native feature workflow: Skill + CLI + Git & Agent Hooks.**
4
+
5
+ [中文文档](./README.zh-CN.md)
6
+
7
+ `featflow` gives human developers and AI coding agents (Codex, Claude Code, Cursor, Antigravity, and any Agent Skills-compatible client) a disciplined, resumable engineering loop:
8
+
9
+ 1. **Read-only Discovery** before touching files or branches.
10
+ 2. **Concrete Plan & Explicit Approval** before implementation.
11
+ 3. **Isolated Git Worktrees** per task branch so parallel sessions never collide.
12
+ 4. **Canonical Feature & Program Records** under `features/` so long-running tasks survive context compaction, session handoffs, and multi-phase initiatives.
13
+ 5. **Programmatic Guardrails** via Git hooks and optional Coding Agent `PreToolUse` / `UserPromptSubmit` / `Stop` hooks that actually enforce branch protection and plan completeness.
14
+
15
+ Zero runtime dependencies. Pure Node.js ESM (`>=20`). Cross-platform (macOS, Linux, Windows).
16
+
17
+ ---
18
+
19
+ ## Flexible Adoption (Global-First or Repo-Embedded)
20
+
21
+ Install `featflow` **once globally** and adapt its footprint per repository — no need to add dependencies or boilerplate to every project:
22
+
23
+ | Mode | Footprint in target repo | Best for |
24
+ | --- | --- | --- |
25
+ | **1. Zero-Footprint Global (Recommended)** | **0 files** (uses built-in templates via `featflow new --local` and `.git/hooks/` via `featflow hooks install --local`) | Personal repos, Python/Go/Rust repos, contributing to external OSS repos without touching tracked files |
26
+ | **2. Lightweight (`featflow init --minimal`)** | **`.featflow.json` + managed `AGENTS.md` block + local `.git/hooks/`** (no `package.json`, lockfile, or boilerplate dirs) | Multi-repo developers and teams who install `featflow` once globally and want one-command auto-detected onboarding |
27
+ | **3. Team Embedded (`devDependency`)** | `package.json` + `.featflow.json` + `AGENTS.md` block + synced Skill/templates/`.githooks/` + CI `featflow sync --check` | Large JS/TS teams requiring identical locked versions across all contributors and CI |
28
+
29
+ ---
30
+
31
+ ## Quick Start
32
+
33
+ ### Option A — Global Install (Recommended, works across all repos & languages)
34
+
35
+ ```bash
36
+ # 1. Install the CLI globally once (or pin via GitHub tag: github:daniel-style/featflow#v0.6.3)
37
+ npm install -g @danielstyle/featflow
38
+
39
+ # 2. Install the Agent Skill globally once (Codex, Claude Code, Cursor, Antigravity)
40
+ npx skills add https://github.com/daniel-style/featflow --skill featflow -g
41
+ ```
42
+
43
+ Use immediately inside **any** Git repository (zero repo files modified):
44
+
45
+ ```bash
46
+ # Optional: enable local branch-protection & auto-cleanup hooks in .git/hooks/ (0 tracked files)
47
+ featflow hooks install --local
48
+
49
+ # Create a task branch in a dedicated worktree
50
+ featflow worktree feat/oauth-pkce
51
+
52
+ # Draft a feature plan (stored locally in .featflow/features/ via .git/info/exclude)
53
+ cd ../my-repo-worktrees/feat-oauth-pkce
54
+ featflow new oauth-pkce --local
55
+
56
+ # After verifying & committing, merge back and clean up automatically
57
+ featflow finish feat/oauth-pkce
58
+ ```
59
+
60
+ Want one-command project onboarding (auto-detected `baseBranch`, `productPaths`, `verifyCommands`, managed `AGENTS.md` workflow block, and local `.git/hooks/`) without touching `package.json` or copying boilerplate? Run:
61
+
62
+ ```bash
63
+ featflow init --minimal
64
+ ```
65
+
66
+ ### Option B — Embed in a Team JS/TS Repository
67
+
68
+ ```bash
69
+ npm install -D @danielstyle/featflow
70
+
71
+ # Interactive wizard with checkbox multi-select (workflow guardrails + AI agent hooks):
72
+ npx featflow init
73
+
74
+ # Or one-command full bundle (size budget + pre-commit guard + Regression Guardian + Issues + all 4 AI agent hooks):
75
+ npx featflow init --preset full --yes
76
+
77
+ # Or non-destructively upgrade an existing repo to add universal agent hooks & regression ledger:
78
+ npx featflow init --merge --with-all-hooks --with-regression
79
+ ```
80
+
81
+ `featflow init` automatically injects a non-destructive `<!-- FEATFLOW_START --> ... <!-- FEATFLOW_END -->` workflow block into `AGENTS.md` / `CLAUDE.md` (opt out with `--no-agent-docs`) and keeps it synced via `featflow sync`.
82
+
83
+ ---
84
+
85
+ ## Supported Branch Topologies
86
+
87
+ ### 1. `trunk` Mode (Default — Solo, Small Teams, OSS)
88
+
89
+ ```text
90
+ main (protected)
91
+ ├── feat/oauth-pkce (dedicated worktree)
92
+ └── fix/retry-timeout (dedicated worktree)
93
+ ```
94
+
95
+ - `featflow worktree feat/oauth-pkce` creates `../<repo>-worktrees/feat-oauth-pkce` from `main`.
96
+ - With `"finishTarget": "merge"` (default): `featflow finish feat/oauth-pkce` merges into `main`, pushes if a remote exists (skip with `--no-push`), and removes the clean worktree and local task branch.
97
+ - With `"finishTarget": "pr"` (or `--pr`): `featflow finish feat/oauth-pkce --pr` pushes the branch for a pull request; after GitHub merges it, run `featflow pr-cleanup <pr-number>`.
98
+
99
+ ### 2. `developer-branch` Mode (Multi-Developer High-Velocity Teams)
100
+
101
+ ```text
102
+ main (release, protected)
103
+ └── dev (team integration, protected)
104
+ ├── alice (personal developer branch)
105
+ │ ├── feat/alice-oauth-pkce (task worktree)
106
+ │ └── fix/alice-retry-timeout (task worktree)
107
+ └── bob (personal developer branch)
108
+ ```
109
+
110
+ - Run once per checkout: `featflow setup alice` (creates/tracks `alice` from `origin/dev`, saves `git config featflow.developerBranch alice`, enables hooks).
111
+ - Daily tasks branch from `alice` as `<prefix>/alice-<task>` (never `alice/...`, because Git cannot store both `alice` and `alice/...` refs simultaneously).
112
+ - `featflow finish feat/alice-oauth-pkce` merges into `alice`, pushes `alice`, removes the clean task worktree and local branch, and never merges directly into `dev` or `main`.
113
+ - Team integration (`alice -> dev`) and release promotion (`dev -> main`) happen via explicit pull requests.
114
+
115
+ ---
116
+
117
+ ## CLI Reference
118
+
119
+ | Command | Description |
120
+ | --- | --- |
121
+ | `featflow new <slug> [options]` | Create a feature (or `--program`) record from the repo template or `featflow`'s built-in template, auto-filling timestamps, `owner`, and branch. Pass `--local` to store under `.featflow/features/` (excluded via `.git/info/exclude`, zero tracked files). |
122
+ | `featflow hooks <install\|uninstall\|status>` | Manage Git hooks: `--local` (default) adds/removes fenced blocks inside `.git/hooks/` without modifying repo files or overwriting custom hooks; `--repo` installs tracked `.githooks/`. |
123
+ | `featflow init [options]` | Auto-detect repo config, inject managed `AGENTS.md`/`CLAUDE.md` block, and interactively pick guardrails & AI coding-agent hooks with TUI multi-select checkboxes. Supports `--preset full` (all guardrails + all 4 agent hooks), `--minimal`, `--merge` (non-destructive upgrade of existing repos with auto legacy size baseline), `--agent-hooks <antigravity,claude-code,codex,cursor|all|none>`, and `--yes`. |
124
+ | `featflow sync [options]` | Sync managed Skill, feature templates, `.githooks/`, and `AGENTS.md`/`CLAUDE.md` blocks from the installed `featflow` version without modifying `.featflow.json`, feature records, or custom doc content. Pass `--check` in CI to fail on drift, or `--only skill,templates,githooks,agent-docs`. |
125
+ | `featflow setup [dev-branch]` | Configure personal developer branch (in `developer-branch` mode) and safely enable Git hooks without clobbering Husky/Lefthook. |
126
+ | `featflow status` | Inspect workflow mode, branch/remote status, all worktrees, active/paused feature records, and next recommended step. |
127
+ | `featflow worktree <branch> [path] [base]` | Create a typed task branch in a dedicated sibling worktree and run configured `postWorktreeCreate` commands. |
128
+ | `featflow finish <branch>` | Merge/push a verified task branch, safely exit the task worktree, delete the clean worktree & local branch, and prune other merged task branches. Supports `--no-push`, `--pr`, `--dry-run`, `--keep-worktree`, `--keep-branch`. |
129
+ | `featflow issue <subcommand>` | Optional GitHub Issues closed-loop CLI (`create`, `list`, `view`, `claim`, `review`, `release`, `labels:sync`) powered by `gh`. Atomically preflights worktree creation before claiming, supports optional screenshot uploads via `issues.assetsRepo`, and syncs optional `featflow-issues` Skill via `featflow init --with-issues` / `featflow sync`. |
130
+ | `featflow size-check [options]` | Optional multi-language file line-count budget checker with legacy baseline ratchet (`--changed`, `--update-baseline`, `--json`), configured via `fileSizeBudget` in `.featflow.json`. |
131
+ | `featflow regression <impact\|check\|validate>` | Optional Regression Guardian CLI for YAML/JSON regression ledgers (`regression.ledgerFile`): find impacted bug invariants for changed files, run guard commands, or validate ledger integrity. |
132
+ | `featflow verify [options]` | Run configured `verifyCommands` matching changed files (`--all`, `--with-size`, `--with-regression`, `--dry-run`, `--json`). |
133
+ | `featflow codegraph [bootstrap\|status]` | Initialize or sync local `.codegraph/codegraph.db` index (skips cleanly in CI or when `codegraph` CLI is absent). |
134
+ | `featflow cleanup` | Clean local task branches and clean worktrees already merged into the base/developer branch. Also runs on `post-merge` via `--post-merge`. |
135
+ | `featflow pr-cleanup <pr>` | After a GitHub PR merges (via `gh`), sync the local base branch, remove the clean PR worktree, delete local/remote branch, and prune refs. |
136
+ | `featflow plan-check [path]` | Validate required `Plan Details` headings, placeholder resolution (ignoring code spans/fences), and recorded pre-implementation approval. |
137
+ | `featflow policy <pre-commit\|pre-push>` | Git hook guard blocking direct commits/pushes to protected branches and staged files exceeding `fileSizeBudget` when `enforceInPreCommit: true` (bypass once with `FEATFLOW_BOOTSTRAP=1` / `FEATFLOW_SKIP_SIZE_CHECK=1`). |
138
+ | `featflow hook <antigravity\|claude-code\|codex\|cursor> <event>` | Universal AI coding-agent hook adapter supporting Antigravity (`.agents/hooks.json`), Claude Code (`.claude/settings.json`), OpenAI Codex (`.codex/config.toml`), and Cursor (`.cursor/hooks.json`). |
139
+ | `featflow doctor` | Run repository health checks across Git, config, templates, Skill, hooks, and active feature plan. |
140
+
141
+ ---
142
+
143
+ ## Configuration (`.featflow.json`)
144
+
145
+ ```json
146
+ {
147
+ "mode": "trunk",
148
+ "remote": "origin",
149
+ "requireRemote": false,
150
+ "baseBranch": "main",
151
+ "integrationBranch": "dev",
152
+ "releaseBranch": "main",
153
+ "protectedBranches": ["main"],
154
+ "finishTarget": "merge",
155
+ "developerBranchConfigKey": "featflow.developerBranch",
156
+ "worktreeParent": null,
157
+ "featuresDir": "features",
158
+ "trackFeaturesInGit": true,
159
+ "trackCurrentFeaturePointer": false,
160
+ "prefixes": ["feat", "fix", "chore", "docs", "test", "refactor", "perf", "security"],
161
+ "productPaths": ["src/", "apps/", "services/", "packages/", "lib/"],
162
+ "postWorktreeCreate": [],
163
+ "verifyCommands": {
164
+ "src/": "npm test"
165
+ },
166
+ "dangerousCommands": {
167
+ "blockDestructiveGit": true,
168
+ "blockForcePush": true,
169
+ "blockEnvWrite": true,
170
+ "blockedPackageManagers": []
171
+ },
172
+ "issues": {
173
+ "provider": "github",
174
+ "repo": null,
175
+ "assetsRepo": "owner/issue-assets",
176
+ "assetsBranch": "main",
177
+ "assetsPrefix": "assets",
178
+ "autoWorktree": true
179
+ }
180
+ }
181
+ ```
182
+
183
+ > Note: `"issues"` is completely optional (omitted by default). Only repositories opting into `featflow issue` need it — and `assetsRepo` is only needed when uploading/downloading local screenshots via `--attach` / `--download-images`.
184
+
185
+ ### Notable Design Choices
186
+
187
+ - **No Husky / Lefthook clobbering**: If `git config core.hooksPath` is already set to another manager (e.g., `.husky`), `featflow init --with-githooks` and `featflow setup` refuse to overwrite it and print the exact one-liners to append to your existing hook files.
188
+ - **No `current-feature.md` merge conflicts**: By default, `trackCurrentFeaturePointer` is `false` (added to `.gitignore`), while `features/active/` serves as the canonical multi-worktree active list.
189
+ - **Tracked vs. Local-only `features/`**: Prefer keeping AI planning records out of Git history? Pass `featflow init --local-features` to ignore `features/` while keeping the full Skill, CLI, and plan-gate workflow locally.
190
+ - **Smart `PreToolUse` plan gating**: Unlike naive keyword regexes, `featflow hook` distinguishes read-only shell commands (`rg`, `cat`, `git diff`) from mutating writes, strips Markdown code spans/fences before checking template placeholders, and checks that `Pre-Implementation Approval` is no longer `pending`.
191
+ - **Optional post-worktree hooks**: Need automatic dependency install (`pnpm install --frozen-lockfile --offline`) or local index bootstrap (`codegraph init`) when creating a worktree? Add them to `postWorktreeCreate` in `.featflow.json`.
192
+ - **Multi-repository sync without drift**: Upgrade `featflow` in any project and run `featflow sync` to refresh the managed Skill, templates, and `.githooks/` while keeping `.featflow.json` and active/done records untouched. Add `featflow sync --check` to CI so repositories stay aligned with their pinned `featflow` version.
193
+
194
+ ---
195
+
196
+ ## Development & Testing
197
+
198
+ ```bash
199
+ npm run smoke
200
+ npm test
201
+ ```
202
+
203
+ All tests run with Node's built-in test runner (`node:test`) against isolated temporary Git repositories.
204
+
205
+ ## License
206
+
207
+ [MIT](./LICENSE)
@@ -0,0 +1,163 @@
1
+ # featflow
2
+
3
+ **面向 AI 编程的工程化特性工作流:Skill + CLI + Git / Agent Hooks。**
4
+
5
+ [English README](./README.md)
6
+
7
+ `featflow` 为人类开发者和 AI Coding Agents(Codex、Claude Code、Cursor、Antigravity 等支持 Agent Skills 的工具)提供一套经过高频实战打磨的闭环工作流:
8
+
9
+ 1. **先只读探索(Discovery)**:改代码和建分支前,先读清真实代码、契约与测试。
10
+ 2. **先出方案并等待审批(Pre-Implementation Gate)**:任何写操作之前输出具体方案,获批后再动手。
11
+ 3. **任务级 Git Worktree 隔离**:每个需求/修复独立分支与独立目录,多任务并行互不干扰。
12
+ 4. **结构化 Feature & Program 记录**:在 `features/` 下沉淀需求 brief、详细实现计划、决策与验证结果,跨会话/长周期项目随时可恢复。
13
+ 5. **程序化硬护栏**:通过 Git Hooks 与可选的 Agent Hooks(`PreToolUse` / `UserPromptSubmit` / `Stop`),真正拦截保护分支误写和“计划没填完就改产品代码”。
14
+
15
+ 零第三方运行时依赖,纯 Node.js ESM(`>=20`),支持 macOS / Linux / Windows。
16
+
17
+ ---
18
+
19
+ ## 灵活接入(推荐全局安装,按项目按需选档)
20
+
21
+ **不需要每个项目都内置依赖或拷模板!** 本机全局安装一次后,每个仓库可以按实际情况选择侵入程度:
22
+
23
+ | 模式 | 目标仓库改动 | 适用场景 |
24
+ | --- | --- | --- |
25
+ | **1. 纯全局零入侵(推荐)** | **0 个文件**(`featflow new --local` 用内置模板写到 `.featflow/features/` 并写入 `.git/info/exclude`;`featflow hooks install --local` 装在 `.git/hooks/`) | 个人项目、Python/Go/Rust 等非 JS 项目、给外部开源项目提 PR |
26
+ | **2. 轻量一键接入(`featflow init --minimal`)** | **`.featflow.json` + `AGENTS.md` 托管块 + 本地 `.git/hooks/`**(不动 `package.json`、不拷模板和 Skill 目录) | 多仓库开发者,全局装一次 CLI 后在任意项目一条命令配齐自动探测配置与工作流规则 |
27
+ | **3. 团队项目内置(`devDependency`)** | `package.json` + `.featflow.json` + `AGENTS.md` 托管块 + 同步的 Skill/模板/`.githooks/` + CI `featflow sync --check` | 多人协作 JS/TS 仓库,希望新人 `pnpm install` 零额外步骤且 CI 强锁版本 |
28
+
29
+ ---
30
+
31
+ ## 快速开始
32
+
33
+ ### 方式 A:全局安装(推荐,跨所有项目与语言通用)
34
+
35
+ ```bash
36
+ # 1. 本机全局安装一次 CLI(也可通过 GitHub tag 安装:github:daniel-style/featflow#v0.6.3)
37
+ npm install -g @danielstyle/featflow
38
+
39
+ # 2. 本机全局安装一次 Agent Skill(Codex / Claude Code / Cursor / Antigravity 自动识别)
40
+ npx skills add https://github.com/daniel-style/featflow --skill featflow -g
41
+ ```
42
+
43
+ 在**任意** Git 仓库里立即可用(0 文件入侵):
44
+
45
+ ```bash
46
+ # 可选:在 .git/hooks/ 启用本地保护分支与自动清理钩子(不改仓库任何 tracked 文件)
47
+ featflow hooks install --local
48
+
49
+ # 创建隔离任务 worktree
50
+ featflow worktree feat/oauth-pkce
51
+
52
+ # 用内置模板生成 feature 计划记录(--local 存本地并自动写入 .git/info/exclude)
53
+ cd ../my-repo-worktrees/feat-oauth-pkce
54
+ featflow new oauth-pkce --local
55
+
56
+ # 验证并 commit 后,一键合并收尾并清理 worktree
57
+ featflow finish feat/oauth-pkce
58
+ ```
59
+
60
+ 想在一个新项目或已有项目里一条命令完成自动探测(主干/保护分支、源码目录、测试命令)、注入 `AGENTS.md` 托管块并启用本地钩子,同时不拷冗余模板、不动 `package.json`?直接运行:
61
+
62
+ ```bash
63
+ featflow init --minimal
64
+ ```
65
+
66
+ ### 方式 B:多人 JS/TS 项目内置锁定版本
67
+
68
+ ```bash
69
+ npm install -D @danielstyle/featflow
70
+
71
+ # 交互式初始化向导:TTY 下带多选勾选框,手动勾选护栏模块和要安装的 Agent Hooks
72
+ npx featflow init
73
+
74
+ # 或者一条命令直接开启全家桶(600 行代码限制 + pre-commit 兜底 + 回归守卫 + Issues 闭环 + 四大 Agent Hooks):
75
+ npx featflow init --preset full --yes
76
+
77
+ # 已有项目无损升级(保留原配置,只增量合并新 hooks / 回归账本 / 自动生成历史行数基线):
78
+ npx featflow init --merge --with-all-hooks --with-regression
79
+ ```
80
+
81
+ `featflow init` 默认会用 `<!-- FEATFLOW_START --> ... <!-- FEATFLOW_END -->` 托管块无损写入项目的 `AGENTS.md` / `CLAUDE.md`(可用 `--no-agent-docs` 跳过),后续升级可通过 `featflow sync` 一键同步。
82
+
83
+ ---
84
+
85
+ ## 支持的两种分支模式
86
+
87
+ ### 1. `trunk` 模式(默认:个人 / 小团队 / 开源项目)
88
+
89
+ ```text
90
+ main (保护分支)
91
+ ├── feat/oauth-pkce (独立 worktree)
92
+ └── fix/retry-timeout (独立 worktree)
93
+ ```
94
+
95
+ - `featflow worktree feat/oauth-pkce` 从 `main` 拉出分支并建好 `../<repo>-worktrees/feat-oauth-pkce`。
96
+ - `"finishTarget": "merge"`(默认):`featflow finish feat/oauth-pkce` 合并回 `main`、有远端则推送(可用 `--no-push` 仅本地),并自动删掉干净的 worktree 和任务分支。
97
+ - `"finishTarget": "pr"`(或命令加 `--pr`):`featflow finish feat/oauth-pkce --pr` 推送任务分支供提 PR;合并后执行 `featflow pr-cleanup <pr-number>` 同步 `main` 并清理本地环境。
98
+
99
+ ### 2. `developer-branch` 模式(多人高频协作团队)
100
+
101
+ ```text
102
+ main (发布分支,受保护)
103
+ └── dev (团队集成分支,受保护)
104
+ ├── alice (个人长期开发分支)
105
+ │ ├── feat/alice-oauth-pkce (任务 worktree)
106
+ │ └── fix/alice-retry-timeout (任务 worktree)
107
+ └── bob (个人长期开发分支)
108
+ ```
109
+
110
+ - 每个本地克隆首次执行一次:`featflow setup alice`(基于 `origin/dev` 创建/跟踪 `alice`,写入 `git config featflow.developerBranch alice`,并安全启用 hooks)。
111
+ - 日常任务从 `alice` 分叉,命名为 `<prefix>/alice-<task>`(不要用 `alice/...`,因为 Git 不允许同名分支与命名空间前缀并存)。
112
+ - `featflow finish feat/alice-oauth-pkce` 合回并推送 `alice`,清理干净的任务 worktree 与本地分支,**绝不直接改动 `dev` 或 `main`**。
113
+ - 需要团队集成(`alice -> dev`)或发布(`dev -> main`)时再显式提 PR。
114
+
115
+ ---
116
+
117
+ ## 常用 CLI 命令
118
+
119
+ | 命令 | 说明 |
120
+ | --- | --- |
121
+ | `featflow new <slug>` | 使用项目模板或 `featflow` 内置模板新建 feature(或 `--program`)记录,自动填入时间戳、`owner` 与分支;加 `--local` 存到 `.featflow/features/` 并写入 `.git/info/exclude` 实现零入侵。 |
122
+ | `featflow hooks <install\|uninstall\|status>` | 管理 Git hooks:`--local`(默认)在 `.git/hooks/` 中无损增删托管块,保留已有自定义 hook 且不改仓库文件;`--repo` 生成入库的 `.githooks/`。 |
123
+ | `featflow init` | 自动探测项目配置、无损注入 `AGENTS.md`/`CLAUDE.md` 托管块,并在 TTY 下提供方向键/空格多选勾选框让用户勾选护栏模块和四大 Agent Hooks。支持 `--preset full`(一键全家桶)、`--minimal`、`--merge`(老项目无损增量升级并自动生成历史行数基线)、`--agent-hooks <antigravity,claude-code,codex,cursor\|all\|none>` 与 `--yes`。 |
124
+ | `featflow sync` | 从当前安装的 `featflow` 同步更新 Skill、模板、`.githooks/` 与 `AGENTS.md`/`CLAUDE.md` 托管块,不改动 `.featflow.json`、已有记录及托管块外的自定义文档。支持 `--check` 放进 CI 防漂移、`--only skill,templates,githooks,agent-docs` 按需同步。 |
125
+ | `featflow setup [branch]` | 初始化个人开发分支(`developer-branch` 模式)并安全配置 Git hooks。 |
126
+ | `featflow status` | 查看当前模式、分支状态、所有 worktree、进行中/暂停中的 feature 记录和下一步建议。 |
127
+ | `featflow worktree <branch>` | 为任务分支创建独立 worktree,并自动执行 `.featflow.json` 中配置的 `postWorktreeCreate` 命令。 |
128
+ | `featflow finish <branch>` | 完成并收尾任务分支(合并/推送、自动切出待删 worktree、移除干净 worktree 与本地分支)。支持 `--no-push`、`--pr`、`--dry-run`、`--keep-worktree`、`--keep-branch`。 |
129
+ | `featflow issue <subcommand>` | 可选的 GitHub Issues 闭环 CLI(`create` / `list` / `view` / `claim` / `review` / `release` / `labels:sync`,仅在调用时依赖 `gh`)。认领前先预检本地 worktree 再改远端状态,支持通过 `.featflow.json` 的 `issues.assetsRepo` 托管截图,并可通过 `featflow init --with-issues` / `featflow sync` 同步可选 `featflow-issues` Skill。 |
130
+ | `featflow size-check [options]` | 可选的多语言文件行数预算守卫(支持历史基线只减不增棘轮、`--changed`、`--update-baseline`、`--json` 及 `post-tool-use` 即时拦截),通过 `.featflow.json` 的 `fileSizeBudget` 按需启用。 |
131
+ | `featflow regression <impact\|check\|validate>` | 可选的回归守卫账本 CLI(支持 YAML/JSON 账本):按改动文件检索命中的历史 Bug 不变量、运行守卫命令或校验账本完整性,配套可选 `featflow-regression` Skill。 |
132
+ | `featflow verify [options]` | 按改动文件匹配执行 `.featflow.json` 中的 `verifyCommands`(支持 `--all`、`--with-size`、`--with-regression`、`--dry-run`、`--json`)。 |
133
+ | `featflow codegraph [bootstrap\|status]` | 一键初始化或同步本地 `.codegraph/codegraph.db` 索引(CI 环境或未装 CLI 时静默跳过)。 |
134
+ | `featflow cleanup` | 清理已合入目标分支且工作区干净的本地任务分支与 worktree(也挂在 `post-merge` 钩子自动执行)。 |
135
+ | `featflow pr-cleanup <pr>` | GitHub PR 合并后(依赖 `gh` CLI)同步目标基线分支、删除干净 worktree 与本地/远端分支并 prune。 |
136
+ | `featflow plan-check [path]` | 校验当前 active feature 记录的 `Plan Details` 章节完整度、占位符清理与审批状态。 |
137
+ | `featflow policy <pre-commit\|pre-push>` | Git hooks 护栏:拦截保护分支直提交/直推送,以及 `enforceInPreCommit: true` 时拦截超出 `fileSizeBudget` 的暂存文件(一次性放行可用 `FEATFLOW_BOOTSTRAP=1` / `FEATFLOW_SKIP_SIZE_CHECK=1`)。 |
138
+ | `featflow hook <antigravity\|claude-code\|codex\|cursor> <event>` | 通用 AI Coding Agent Hook 适配器,原生支持 Antigravity(`.agents/hooks.json`)、Claude Code(`.claude/settings.json`)、OpenAI Codex(`.codex/config.toml`)与 Cursor(`.cursor/hooks.json`)。 |
139
+ | `featflow doctor` | 体检 Git、配置、模板、Skill、Hooks 与当前 feature 计划状态。 |
140
+
141
+ ---
142
+
143
+ ## 关键工程细节
144
+
145
+ - **绝不覆盖已有 Husky / Lefthook**:检测到 `core.hooksPath` 已被其他工具占用时不会粗暴覆盖,而是提示如何把单行 `featflow policy ...` 接入现有钩子。
146
+ - **消除 `current-feature.md` 合并冲突**:默认忽略 `features/current-feature.md`,用 `features/active/` 作为多 worktree 唯一真源;需要共享指针时可加 `--track-pointer`。
147
+ - **支持记录不入库(本地模式)**:不希望把 AI 规划文档提交进 Git 历史?运行 `featflow init --local-features` 即可将 `features/` 写入 `.gitignore`,同时保留完整的规划校验与 worktree 自动化。
148
+ - **更精准的 `PreToolUse` 校验**:区分只读命令(`rg`、`cat`、`git diff`)与真实写操作,检测占位符前自动剥离 Markdown 代码块与行内代码避免误拦,且校验 `Pre-Implementation Approval` 非 `pending`。
149
+ - **可扩展的 `postWorktreeCreate` 钩子**:需要在建完 worktree 后自动装依赖(如 `pnpm install --frozen-lockfile --offline`)或构建索引(如 `codegraph init`),直接配置到 `.featflow.json` 的 `postWorktreeCreate` 数组即可。
150
+ - **多仓库一键同步防漂移**:在业务仓库升级 `featflow` 后运行 `featflow sync` 即可同步最新 Skill、模板与 `.githooks/`,不会覆盖项目自身的 `.featflow.json`;把 `featflow sync --check` 放进 CI 可自动防止文档/模板与 CLI 版本脱节。
151
+
152
+ ---
153
+
154
+ ## 本地测试
155
+
156
+ ```bash
157
+ npm run smoke
158
+ npm test
159
+ ```
160
+
161
+ ## 开源协议
162
+
163
+ [MIT](./LICENSE)
@@ -0,0 +1,113 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { readFileSync } from "node:fs";
4
+ import path from "node:path";
5
+
6
+ import { packageRoot } from "../src/config.mjs";
7
+ import { runCleanup } from "../src/commands/cleanup.mjs";
8
+ import { runCodegraph } from "../src/commands/codegraph.mjs";
9
+ import { runDoctor } from "../src/commands/doctor.mjs";
10
+ import { runFinish } from "../src/commands/finish.mjs";
11
+ import { runHook } from "../src/commands/hook-cmd.mjs";
12
+ import { runHooks } from "../src/commands/hooks-cmd.mjs";
13
+ import { runInit } from "../src/commands/init.mjs";
14
+ import { runIssue } from "../src/commands/issue.mjs";
15
+ import { runNew } from "../src/commands/new.mjs";
16
+ import { runPlanCheck } from "../src/commands/plan-check.mjs";
17
+ import { runPolicy } from "../src/commands/policy-cmd.mjs";
18
+ import { runPrCleanup } from "../src/commands/pr-cleanup.mjs";
19
+ import { runRegression } from "../src/commands/regression.mjs";
20
+ import { runSetup } from "../src/commands/setup.mjs";
21
+ import { runSizeCheck } from "../src/commands/size-check.mjs";
22
+ import { runStatus } from "../src/commands/status.mjs";
23
+ import { runSync } from "../src/commands/sync.mjs";
24
+ import { runVerify } from "../src/commands/verify.mjs";
25
+ import { runWorktree } from "../src/commands/worktree.mjs";
26
+
27
+ const pkg = JSON.parse(readFileSync(path.join(packageRoot, "package.json"), "utf8"));
28
+
29
+ const usage = `
30
+ featflow v${pkg.version} — AI-native feature workflow (Skill + CLI + Hooks)
31
+
32
+ Usage:
33
+ featflow <command> [options]
34
+
35
+ Commands:
36
+ new Create a feature or program record from repo or built-in template (--local for zero-footprint)
37
+ hooks Install/uninstall/inspect Git hooks (--local into .git/hooks/ or --repo into .githooks/)
38
+ init Auto-detect repo config, inject AGENTS.md block, and scaffold featflow (--minimal for lightweight)
39
+ sync Sync managed Skill, templates, .githooks, and AGENTS.md blocks (--check for CI)
40
+ setup Configure developer branch (if applicable) and safely enable Git hooks
41
+ status Show workflow mode, branch/worktree state, active features, and next step
42
+ worktree Create a typed task branch in a dedicated Git worktree
43
+ finish Merge/push a verified task branch and clean up its worktree
44
+ issue GitHub Issues closed-loop CLI (create | list | view | claim | review | release | labels:sync)
45
+ size-check Check files against configured fileSizeBudget (with legacy baseline ratchet)
46
+ regression Inspect or validate the regression memory ledger (impact | check | validate)
47
+ verify Run verifyCommands matching changed files (--all for full)
48
+ codegraph Bootstrap or inspect local CodeGraph index (.codegraph/codegraph.db)
49
+ cleanup Remove clean worktrees and local task branches already merged into base
50
+ pr-cleanup Sync base branch and clean up local worktree/branch after a GitHub PR merge
51
+ plan-check Validate that the active feature record has complete, approved Plan Details
52
+ policy Run Git hook guards (pre-commit | pre-push)
53
+ hook Run AI coding-agent hook adapters (antigravity | claude-code | codex | cursor)
54
+ doctor Check repository configuration, hooks, templates, and active feature health
55
+
56
+ Global Options:
57
+ -h, --help Show help
58
+ -v, --version Show version
59
+
60
+ Run "featflow <command> --help" for command-specific options.
61
+ `.trim();
62
+
63
+ const commands = {
64
+ new: runNew,
65
+ hooks: runHooks,
66
+ init: runInit,
67
+ sync: runSync,
68
+ setup: runSetup,
69
+ status: runStatus,
70
+ worktree: runWorktree,
71
+ finish: runFinish,
72
+ issue: runIssue,
73
+ issues: runIssue,
74
+ "size-check": runSizeCheck,
75
+ regression: runRegression,
76
+ "regression-impact": (rest) => runRegression(rest, "impact"),
77
+ verify: runVerify,
78
+ codegraph: runCodegraph,
79
+ cleanup: runCleanup,
80
+ "pr-cleanup": runPrCleanup,
81
+ "plan-check": runPlanCheck,
82
+ policy: runPolicy,
83
+ hook: runHook,
84
+ doctor: runDoctor,
85
+ };
86
+
87
+ async function main() {
88
+ const [command, ...rest] = process.argv.slice(2);
89
+
90
+ if (!command || command === "-h" || command === "--help") {
91
+ console.log(usage);
92
+ return;
93
+ }
94
+
95
+ if (command === "-v" || command === "--version") {
96
+ console.log(pkg.version);
97
+ return;
98
+ }
99
+
100
+ const handler = commands[command];
101
+ if (!handler) {
102
+ console.error(`error: Unknown command "${command}".\n`);
103
+ console.error(usage);
104
+ process.exit(1);
105
+ }
106
+
107
+ await handler(rest);
108
+ }
109
+
110
+ main().catch((error) => {
111
+ console.error(`error: ${error instanceof Error ? error.message : String(error)}`);
112
+ process.exit(1);
113
+ });
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@danielstyle/featflow",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.6.3",
4
+ "description": "AI-native feature workflow: Skill + CLI + Git/Agent Hooks for discovery-first planning, Git worktree isolation, GitHub Issues closed loop, and safe branch lifecycles.",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "author": "Daniel",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/daniel-style/featflow.git"
11
+ },
12
+ "homepage": "https://github.com/daniel-style/featflow#readme",
13
+ "bugs": {
14
+ "url": "https://github.com/daniel-style/featflow/issues"
15
+ },
16
+ "keywords": [
17
+ "ai-agent",
18
+ "agent-skills",
19
+ "workflow",
20
+ "git-worktree",
21
+ "feature-planning",
22
+ "codex",
23
+ "claude-code",
24
+ "antigravity",
25
+ "cursor",
26
+ "cli",
27
+ "hooks"
28
+ ],
29
+ "engines": {
30
+ "node": ">=20.0.0"
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "bin": {
36
+ "featflow": "bin/featflow.mjs"
37
+ },
38
+ "exports": {
39
+ ".": "./src/index.mjs",
40
+ "./config": "./src/config.mjs",
41
+ "./git": "./src/git.mjs",
42
+ "./changed-files": "./src/changed-files.mjs",
43
+ "./plan": "./src/plan.mjs",
44
+ "./policy": "./src/policy.mjs",
45
+ "./hooks": "./src/hooks-core.mjs",
46
+ "./issues": "./src/issues.mjs",
47
+ "./size-check": "./src/size-check.mjs",
48
+ "./regression": "./src/regression.mjs"
49
+ },
50
+ "files": [
51
+ "bin/",
52
+ "src/",
53
+ "skills/",
54
+ "templates/",
55
+ "README.md",
56
+ "README.zh-CN.md",
57
+ "LICENSE"
58
+ ],
59
+ "scripts": {
60
+ "test": "node --test",
61
+ "smoke": "node bin/featflow.mjs --help",
62
+ "lint:size": "node bin/featflow.mjs size-check"
63
+ }
64
+ }